package com.example.bili.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.bili.R;
import com.example.bili.allbean.HisplaypageBean2;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

/**
 * 作    者 ： 文欢
 * 时    间 ： 2017/3/10.
 * 描    述 ：
 * 修改时间 ：
 */

public class WHisplayPageAdapterf extends RecyclerView.Adapter<WHisplayPageAdapterf.MyViewHolder> {
    Context context;
    List<HisplaypageBean2.ResultBean> result1;
    private OnRVitemClickListener onRVitemClickListener;

    public WHisplayPageAdapterf(Context context, List<HisplaypageBean2.ResultBean> result1) {
        this.context = context;
        this.result1 = result1;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
       MyViewHolder myViewHolder = new MyViewHolder(LayoutInflater.from(
                context).inflate(R.layout.w_hisplaypage_ritem3, parent, false));
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.item3_name.setText(result1.get(position).getTitle2());
        holder.item3_context.setText(result1.get(position).getDesc());
        holder.item3_img.setImageURI(result1.get(position).getCover());
        holder.item3_img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onRVitemClickListener.onClickListener(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return result1.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {

        private final SimpleDraweeView item3_img;
        private final TextView item3_name;
        private final TextView item3_context;

        public MyViewHolder(View itemView) {
            super(itemView);
            item3_img = (SimpleDraweeView) itemView.findViewById(R.id.item3_img);
            item3_name = (TextView) itemView.findViewById(R.id.item3_name);
            item3_context = (TextView) itemView.findViewById(R.id.item3_context);
        }
    }

    public interface OnRVitemClickListener {
        void onClickListener(int position);
    }

    public void setOnRVitemClickListener(OnRVitemClickListener onRVitemClickListener) {
        this.onRVitemClickListener = onRVitemClickListener;
    }
}
